package com.example;

import android.app.Activity;
import android.content.Context;
import android.net.wifi.WifiManager;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

public class WifiActivity extends Activity {

    private WifiManager wifiManager;
    /**
     * Called when the activity is first created.
     */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        Button start_wifi = (Button) findViewById(R.id.start_wifi);
        Button stop_wifi = (Button) findViewById(R.id.stop_wifi);
        Button check = (Button) findViewById(R.id.check_wifi);

        start_wifi.setOnClickListener(new StartWifiListener());
        stop_wifi.setOnClickListener(new StopWifiListener());
        check.setOnClickListener(new CheckListener());
    }

    class StartWifiListener implements View.OnClickListener {

        @Override
        public void onClick(View v) {

            wifiManager = (WifiManager) WifiActivity.this.getSystemService(Context.WIFI_SERVICE);
            wifiManager.setWifiEnabled(true);
            System.out.println("Wifi status is " + wifiManager.getWifiState());
            Toast.makeText(WifiActivity.this,"当前wifi状是：" + wifiManager.getWifiState(), Toast.LENGTH_LONG);
        }
    }

    class StopWifiListener implements View.OnClickListener {

        @Override
        public void onClick(View v) {
            wifiManager = (WifiManager) WifiActivity.this.getSystemService(Context.WIFI_SERVICE);
            wifiManager.setWifiEnabled(false);
            System.out.println("Wifi status is " + wifiManager.getWifiState());
            Toast.makeText(WifiActivity.this,"当前wifi状是：" + wifiManager.getWifiState(), Toast.LENGTH_LONG);
        }
    }

    class CheckListener implements View.OnClickListener {

        @Override
        public void onClick(View v) {
            wifiManager = (WifiManager) WifiActivity.this.getSystemService(Context.WIFI_SERVICE);
            System.out.println("Wifi status is " + wifiManager.getWifiState());
            Toast.makeText(WifiActivity.this,"当前wifi状是：" + wifiManager.getWifiState(), Toast.LENGTH_LONG);        }
    }
}
